
Part 5
In my implementation of adaptive sampling within a ray tracing algorithm, I begin by setting a
base number of samples per pixel. My goal is to dynamically adjust this number based on the
complexity of each pixel's content. Here’s how I approach it:
Initial Setup:
I start with a predefined number of samples for each pixel. I also initialize variables to keep track
of the accumulated color (avgColor) and the statistics needed for the adaptive sampling decision
(s1 and s2 for sum of illuminance and its square, respectively).
Sampling and Ray Tracing:
In a loop, I generate camera rays for each sample. For this, I calculate normalized coordinates
within the pixel, ensuring each sample covers a different part of the pixel. I trace each ray
through the scene and estimate the radiance along it. I accumulate these radiance estimates to
form the average color for the pixel, and simultaneously, I update s1 and s2 for the adaptive
sampling calculations.
Adaptive Decision:
Every few samples (as defined by samplesPerBatch), I pause to assess the variance in the
samples I've taken so far. Using s1 and s2, I calculate the mean and standard deviation of the
sample illuminances. With these, I determine the confidence interval of the mean. If this interval
is smaller than a set tolerance level (defined by maxTolerance) relative to the mean, I interpret it
as the pixel's color being sufficiently resolved. In that case, I stop sampling early for that pixel.
Finalizing Pixel Color:
Once I exit the sampling loop—either because I've reached the maximum number of samples or
decided to stop early based on the adaptive criteria—I finalize the average color for the pixel.
This involves dividing the accumulated color by the actual number of samples taken. I then
update the pixel's color in the image.
In essence, my adaptive sampling strategy allows me to focus computational resources more
effectively. Pixels in complex areas (with high detail or noise) receive more samples, while
simpler areas get fewer samples. This approach helps me achieve a good balance between image
quality and rendering efficiency. The adaptiveness is finely controlled by samplesPerBatch and
maxTolerance, which I tune based on the specific needs of the scene I'm rendering.
Rendered Images and rate images: